﻿Imports Phila
Imports Phila.Sql
Imports Phila.CommonClasses

Public Class EditNews
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If IsPostBack = False Then
                If Not Request.QueryString("nid") Is Nothing Then
                    fillData(Request.QueryString("nid"))
                End If
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub fillData(ByVal Id As Integer)
        Dim arr As Array
        arr = RetriveData("Select Id, Title, Description, IsActive, IsArchive, Date from ptn_News where Id=" & Id, 5)
        txtTitle.Text = arr(1)
        txtDate.Text = arr(5)
        txtDescription.Content = arr(2)
        chkActive.Checked = arr(3)
        chkArchive.Checked = arr(4)
    End Sub


    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
        Try
            Dim strActive, strArchive As String
            If chkActive.Checked = True Then
                strActive = 1
            Else
                strActive = 0
            End If
            If chkArchive.Checked = True Then
                strArchive = 1
            Else
                strArchive = 0
            End If
            If Not Request.QueryString("nid") Is Nothing Then
                Insert_Update_Delete_Record("UPDATE ptn_News Set Title='" & Server.HtmlEncode(txtTitle.Text.Replace("'", "&#039;")) & "', Description='" & txtDescription.Content.Replace("'", "&#039;") & "', Date='" & txtDate.Text & "', IsActive=" & strActive & ", IsArchive=" & strArchive & ", UpdatedDate='" & Date.Now & "' where Id=" & Server.HtmlEncode(Request.QueryString("nid")))
            Else
                Insert_Update_Delete_Record("INSERT INTO ptn_News (Title, Description, Date, IsActive, IsArchive, UpdatedDate) values('" & txtTitle.Text.Replace("'", "&#039;") & "','" & txtDescription.Content.Replace("'", "&#039;") & "','" & txtDate.Text & "'," & strActive & "," & strArchive & ",'" & Date.Now & "')")
            End If
            Response.Redirect("ViewNews.aspx")
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCancel.Click
        Response.Redirect("ViewNews.aspx")
    End Sub
End Class